
module.exports = function (formArr, reqUrl, callback) {
    let parmas = []
    for (let key in formArr) {
        if (/^\s$/.test(formArr[key]) || formArr[key] == "") {
            console.log(key+"还没填写");
            this.$message.error("请填写完信息！")
            return
        }
        parmas.push(`${key}=${formArr[key]}&`)
    }
    parmas[parmas.length - 1] = parmas[parmas.length - 1].replace(/&/g,'')
    fetch(`/api/${reqUrl}`, {
        method: "post",
        body: parmas.toString().replace(/,/g,''),
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
        },
    })
        .then((res) => res.json())
        .then((res) => {
            if (res.status == "0") {
                this.$message({
                    type: "success",
                    message: "添加成功!",
                });
                callback.call(this);
                // 添加完后清空表单
                for (let a in this.formInline) {
                    if (a != "date")
                        this.formInline[a] = ""
                    else
                        this.formInline[a] = new Date().toLocaleString()
                }
            } else {
                this.$message.error("服务器繁忙，请稍后再试！");
            }
        });
}